﻿using System;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace OmcSocketClient {

    public static class omcSocketClient {
        
        private const string HOST_NAME = "localhost";
        private const int PORT = 5555;

        public static string send( string data ) {
            
            TcpClient tcpClient;
            StreamReader fromOMC;
            StreamWriter toOMC;
            String result;

            try {
                //TODO Jirka: tady to pada...
                tcpClient = new TcpClient( HOST_NAME , PORT );                
                fromOMC = new StreamReader( tcpClient.GetStream() );
                toOMC = new StreamWriter( tcpClient.GetStream() );
                toOMC.WriteLine( data );
                toOMC.Flush();
                result = fromOMC.ReadToEnd();
            } catch( SocketException ex ) {
                result = ex.Message;
            }
            
            return result;

        }

    }

}
